package com.action.setting;

import java.io.IOException;
import java.util.List;

import com.action.common.Ajax;
import com.action.common.WEB;
import com.opensymphony.xwork2.ActionSupport;
import com.pojo.basic.DEPT;
import com.pojo.basic.SALM;
import com.pojo.job.pa.PAJobPriviledge;
import com.pojo.job.pa.PAMenu;
import com.service.basic.IDEPTService;
import com.service.basic.ISALMService;
import com.service.job.pa.IJobPriviledgeService;
import com.service.job.pa.IPAMenuService;
import com.util.ActionLog;

public class PAJobAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private Integer  id;
	private IJobPriviledgeService jobPriviledgeService;
	private IDEPTService deptService;
	private ISALMService salmService;
	private IPAMenuService paMenuService;
	private List<SALM> salms;
	private List<DEPT> depts;
	private List<PAJobPriviledge> pajobpriviledges;
	private PAMenu pamenu;
	private String datas;
	
	//setter getter
	
	public Integer getId() {
		return id;
	}

	public String getDatas() {
		return datas;
	}

	public void setDatas(String datas) {
		this.datas = datas;
	}

	public List<PAJobPriviledge> getPajobpriviledges() {
		return pajobpriviledges;
	}

	public void setPajobpriviledges(List<PAJobPriviledge> pajobpriviledges) {
		this.pajobpriviledges = pajobpriviledges;
	}

	public List<DEPT> getDepts() {
		return depts;
	}

	public void setDepts(List<DEPT> depts) {
		this.depts = depts;
	}

	public void setDeptService(IDEPTService deptService) {
		this.deptService = deptService;
	}

	public PAMenu getPamenu() {
		return pamenu;
	}

	public void setPamenu(PAMenu pamenu) {
		this.pamenu = pamenu;
	}

	public void setPaMenuService(IPAMenuService paMenuService) {
		this.paMenuService = paMenuService;
	}

	public List<SALM> getSalms() {
		return salms;
	}

	public void setSalms(List<SALM> salms) {
		this.salms = salms;
	}

	public void setSalmService(ISALMService salmService) {
		this.salmService = salmService;
	}

	public void setJobPriviledgeService(
			IJobPriviledgeService jobPriviledgeService) {
		this.jobPriviledgeService = jobPriviledgeService;
	}

	public void setId(Integer id) {
		this.id = id;
	}
	
	//action method
	
	public String initPAJobPermissionData(){
		ActionLog.info(JobMenuAction.class,"["+WEB.getClassName(this.getClass())+"]:系统设置-->表单管理-->行政人事-->權限設定【初始化表单權限數據】");
		this.setPajobpriviledges(jobPriviledgeService.findByRightJoinSALM(this.getId(),0));
		this.setPamenu(paMenuService.get(this.getId()));
		this.setSalms( salmService.findAllSALM());
		this.setDepts(deptService.findAllDEPT());
		return SUCCESS;
	}

	public void savaJobPriviledgeData(){
		ActionLog.info(this.getClass(), "["+WEB.getClassName(this.getClass())+"]:系统设置-->表单管理-->行政人事-->表單權限設定【保存用戶權限設定】");
		jobPriviledgeService.sava(this.getId(), datas,0);
		try {
			Ajax.sendMsgAjax("success");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public String initPAJobETPermissionData(){
		ActionLog.info(JobMenuAction.class,"["+WEB.getClassName(this.getClass())+"]:系统设置-->表单管理-->行政人事-->權限設定【初始化表单ET權限數據】");
		this.setPajobpriviledges(jobPriviledgeService.findByRightJoinSALM(this.getId(),1));
		this.setPamenu(paMenuService.get(this.getId()));
		this.setSalms( salmService.findAllSALM());
		this.setDepts(deptService.findAllDEPT());
		return SUCCESS;
	}
	
	public void savaJobETPriviledgeData(){
		ActionLog.info(this.getClass(), "["+WEB.getClassName(this.getClass())+"]:系统设置-->表单管理-->行政人事-->表單ET權限設定【保存用戶權限設定】");
		jobPriviledgeService.sava(this.getId(), datas,1);
		try {
			Ajax.sendMsgAjax("success");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
